package com.sun.huazhi.aitaskservice.controller;

import com.caifeng.domain.common.convention.result.Result;
import com.caifeng.domain.common.convention.result.Results;
import com.sun.huazhi.aitaskservice.DTO.request.DynamicVideoRequestDTO;
import com.sun.huazhi.aitaskservice.common.Enum.TasksStatus;
import com.sun.huazhi.aitaskservice.dao.entity.VideoTasksDO;
import com.sun.huazhi.aitaskservice.service.DynamicVideoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/dynamicvideo")
@Tag(name = "视频管理", description = "视频增删改查接口") // 类级别的描述
public class DynamicVideoController {

    @Autowired
    private final DynamicVideoService dynamicVideoService;


    /**
     * 创建动态视频
     */
    @PostMapping("/create")
    @Operation(summary = "创建视频", description = "根据用户id和用户输入生成视频")
    public Result<String> createDynamicVideo(@RequestBody DynamicVideoRequestDTO requestParam) {
        return Results.success(dynamicVideoService.createTask(requestParam));
    }

    /**
     * 查询任务状态
     * @param taskId 视频id
     */
    @GetMapping("/{taskId}/status")
    @Operation(summary = "查询视频任务状态")
    public Result<String> getStatus(@PathVariable String taskId) {
        return Results.success(dynamicVideoService.getStatus(taskId));
    }

    /**
     * 获取已生成的视频
     */
    @GetMapping("/result")
    @Operation(summary = "获取视频")
    public Result<String> getVideoUrl(@RequestParam String taskId) {
        return Results.success(dynamicVideoService.getVideoUrl(taskId));
    }

    /**
     * 查看历史生成记录
     * @param userId
     */
    @GetMapping("/history")
    @Operation(summary = "查询用户历史生成视频记录")
    public Result<List<VideoTasksDO>> getUserHistory(@RequestParam Long userId) {
        return Results.success(dynamicVideoService.getUserHistory(userId));
    }

    /**
     * 删除某个视频
     * @param taskId
     */
    @DeleteMapping("/delete")
    @Operation(summary = "删除视频")
    public Result<Void> deleteTask(@RequestParam String taskId) {
        dynamicVideoService.deleteTask(taskId);
        return Results.success();
    }
}
